package com.minelx.datamicroscope.querylanguage.data;

import com.alibaba.fastjson.JSONObject;

import java.util.Objects;

public final class BinaryOperatorCondition implements Condition {

	private final String key;

	private final String operator;

	private final String value;

	public BinaryOperatorCondition(String key, String operator, String value) {
		this.key = key;
		this.operator = operator;
		this.value = value;
	}

	@Override
	public JSONObject toJSON() {
		JSONObject result = new JSONObject();
		result.put("key", key);
		result.put("operator", operator);
		result.put("value", value);
		return result;
	}

	public String key() {
		return key;
	}

	public String operator() {
		return operator;
	}

	public String value() {
		return value;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this) return true;
		if (obj == null || obj.getClass() != this.getClass()) return false;
		BinaryOperatorCondition that = (BinaryOperatorCondition) obj;
		return Objects.equals(this.key, that.key) &&
				Objects.equals(this.operator, that.operator) &&
				Objects.equals(this.value, that.value);
	}

	@Override
	public int hashCode() {
		return Objects.hash(key, operator, value);
	}

	@Override
	public String toString() {
		return "Condition[" +
				"key=" + key + ", " +
				"operator=" + operator + ", " +
				"value=" + value + ']';
	}
}
